﻿@{
    Layout = "_LayoutAdmin";
}

@model FriendLinkSettingsViewModelWrap

<partial name="_SettingsHeader" />

<form id="form-settings" asp-controller="Settings" asp-action="FriendLinkSettings"
      data-ajax-begin="onUpdateSettingsBegin"
      data-ajax-complete="onUpdateSettingsComplete"
      data-ajax-failure="onUpdateSettingsFailed"
      data-ajax-success="onUpdateSettingsSuccess"
      data-ajax="true"
      data-ajax-method="POST">
    <div asp-validation-summary="All" class="text-danger"></div>
    <div class="row">
        <div class="col-md-6">
            <div class="card mb-4">
                <div class="card-header">Friend Link Options</div>
                <ul class="list-group list-group-flush">
                    <li class="list-group-item">
                        <label asp-for="FriendLinkSettingsViewModel.ShowFriendLinksSection" class="control-label"></label>
                        <div class="material-switch float-right">
                            <input @(Model.FriendLinkSettingsViewModel.ShowFriendLinksSection ? "checked=\"checked\"" : "") id="ShowFriendLinksSection" name="ShowFriendLinksSection" type="checkbox" value="true">
                            <label for="ShowFriendLinksSection" class="label-success"></label>
                            <input name="ShowFriendLinksSection" type="hidden" value="false">
                        </div>
                    </li>
                </ul>
                <div class="card-footer">
                    <input id="btn-save-settings" type="submit" value="Save" class="btn btn-success" />
                </div>
            </div>
        </div>
    </div>
</form>

<div class="mb-2">
    <a class="btn btn-outline-success" asp-controller="Settings" asp-action="CreateFriendLink">
        <span class="icon-plus"></span>
        New
    </a>
</div>

@if (null != ViewBag.IsServerError && ViewBag.IsServerError)
{
    <partial name="_ServerErrorMessage" />
}
else
{
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>
                    Title
                </th>
                <th>
                    Link
                </th>
                <th class="table-item-w20">
                    Action
                </th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.FriendLinks.OrderBy(m => m.Title))
            {
                <tr>
                    <td>
                        @item.Title
                    </td>
                    <td>
                        @item.LinkUrl
                    </td>
                    <td>
                        <a asp-controller="Settings" asp-action="EditFriendLink" asp-route-id="@item.Id" class="btn btn-sm btn-primary">Edit</a>
                        <a asp-controller="Settings" asp-action="DeleteFriendLink" asp-route-id="@item.Id" class="btn btn-sm btn-danger">Delete</a>
                    </td>
                </tr>
            }
        </tbody>
    </table>
}